package com.freewater.parking.infrastructure.db;

import com.freewater.parking.domain.parking.Parking;
import com.freewater.parking.domain.common.PlateNumber;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;

@Entity
@Table(name = "parking")
@Getter
@Setter
public class ParkingTable {

    @Id
    private String plateNumber;

    private LocalDateTime checkInTime;

    private LocalDateTime lastPayTime;

    private int totalPaid;

    public ParkingTable() {

    }

    public ParkingTable(Parking parking) {
        this.plateNumber = parking.getPlateNumber().getValue();
        this.checkInTime = parking.getCheckInTime();
        this.lastPayTime = parking.getLastPayTime();
        this.totalPaid = parking.getTotalPaid();
    }

    public Parking toParking() {
        return new Parking(new PlateNumber(this.plateNumber),
                this.checkInTime,
                this.totalPaid,
                this.lastPayTime
        );
    }
}
